package bdd;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import data.Login;

public class ConnectionOracle {

    private static String url = "jdbc:oracle:thin:@//localhost:1522/BASEDL";
    // private String url = "jdbc:oracle:thin:@//10.105.41.142:1521/BASEDL";
    private String user = "invite";
    private String password = "invite";
    private Connection connect = null;

    public Connection getInstance() {
	if (connect == null) {
	    try {
		connect = DriverManager.getConnection(url, user, password);
		return connect;
	    } catch (SQLException sqle) {
		sqle.printStackTrace();
	    }
	}
	return connect;
    }

    public Connection getInstance(String user, String password)
	    throws SQLException {
	if (connect == null) {
	    connect = DriverManager.getConnection(url, user, password);
	}
	return connect;
    }

    public Connection getInstance(Login login) throws SQLException {
	if (connect == null) {
	    try {
		Class.forName("oracle.jdbc.driver.OracleDriver");
	    } catch (ClassNotFoundException e) {
		e.printStackTrace();
	    }
	    connect = DriverManager.getConnection(url, login.getLogin()
		    .toString(), login.getPassword().toString());
	}
	return connect;
    }

    public boolean dropInstance() {
	try {
	    connect.close();
	    connect = null;
	    return true;
	} catch (SQLException e) {
	    e.printStackTrace();
	}
	return false;
    }

    public boolean isNull() {
	return (this.connect == null) ? true : false;
    }
}
